package com.clinic.controller;

import com.clinic.entity.Drug;
import com.clinic.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import java.util.ArrayList;
import java.util.List;

/**
 * (Drug)表控制层
 *
 * @author makejava
 * @since 2020-11-12 15:55:18
 */
@Controller
public class DrugController {
    /**
     * 服务对象
     */
    @Autowired
    private DrugService drugService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ResponseBody
    @GetMapping("/selectOne")
    public Drug selectOne(Integer id) {
        return this.drugService.queryById(id);
    }
    @ResponseBody
    @GetMapping("/Drugs")
    public List<Drug> getAllDrugs(){
        return drugService.getAllDrug();
    }
    @ResponseBody
    @GetMapping("/DrugInsert")
    public Drug insert(Drug drug){
        return drugService.insert(drug);
    }

    @ResponseBody
    @GetMapping("/DrugUpdate")
    public Drug update(Drug drug){
        return drugService.update(drug);
    }

    @RequestMapping(value = "delete",method = RequestMethod.GET)
    @ResponseBody
    public String  delete(@RequestParam(value = "idArry",required = true )String idArry) {
        String[] idlist=idArry.split(",");
        List<String> list=new ArrayList<String>();
        for(int i=0;i<idlist.length;i++){
            list.add(idlist[i]);
        }
        int delete = drugService.delete(list);
        return "redirect:drug/drug";
    }

}